/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Locale;
import javax.faces.component.UIViewRoot;
import javax.faces.event.ValueChangeEvent;
import javax.faces.context.FacesContext;
/**
 *
 * @author java
 */
public class User {

    public String getLang() {
        return lang;
    }

    public void setLang(String lang) {
        this.lang = lang;
    }

    /** Creates a new instance of User */
    public User() {
    }
    private String name = "";
    private String lang = "";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void changeLanguage(ValueChangeEvent e)
    {
// this comming line called by any action function bur for binding functions we must call it our selfs
     System.out.println("new event value = " + e.getNewValue());
     System.out.println("old event value = " + e.getOldValue());
     System.out.println("lang value = " + lang);
     setLang(e.getNewValue().toString());
     String local = "" ;
        if (e.getNewValue().toString().equals("rtl"))
        {
          local = "ar" ;
        }
        else
        {
          local = "en" ;
        }

    //Get current viewRoot
    UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
    //Set its locale to the locale you want to load
    viewRoot.setLocale(new Locale(local));

     /*   if (lang.equals("ltr"))
      {
          lang = "rtl" ;
      }
      else { lang = "ltr" ;}
     */
        FacesContext.getCurrentInstance().renderResponse();
    }
}
